<?php

namespace App\command;

use app\common\MsgType;
use App\model\Mail;
use App\model\Role;
use app\model\User;
use App\service\TradeService;
use GatewayWorker\Lib\Gateway;
use support\Constant;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;


class ClearRes extends Command
{
    protected static $defaultName = 'command:checkRes';
    protected static $defaultDescription = 'command checkRes';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addArgument('type', InputArgument::OPTIONAL, 'Name description');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $type = $input->getArgument('type');//1-金币 2-元宝
        $type = $type ?? 1;
        var_dump($type);

        switch ($type) {
            case 1:
                $roles = Role::query()->where('gold', '>', 20000000)->get();
                $roles = $roles ? $roles->toArray() : [];
                print_r($roles);

                foreach ($roles as $role) {
                    $real_uuid = $role['uuid'] . '-' . $role['role_id'];
                    Gateway::sendToUid($real_uuid, json_encode([
                        'type' => MsgType::TYPE_36,
                        'value' => 20000000,
                    ]));
                }
                break;
            case 2:
                $roles = Role::query()->where('ingot', '>', 50000)->get();
                $roles = $roles ? $roles->toArray() : [];

                foreach ($roles as $role) {
                    $real_uuid = $role['uuid'] . '-' . $role['role_id'];
                    Gateway::sendToUid($real_uuid, json_encode([
                        'type' => MsgType::TYPE_37,
                        'value' => 50000,
                    ]));
                }
                break;

        }


        return self::SUCCESS;

    }

}
